// pages/driver/sign/sign.js
const handler = require("../../../utils/function.js");
var app = getApp(),
  api = require("../../../api.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sign:''
  },
  //获取签名
  getSign:function(e){
    console.log(e)
    var sign=e.detail.value;
    this.setData({ sign})
  },
  getComplain:function(){
    let that=this;
    wx.showLoading({})
    app.request({
      url: api.user.signature,
      method: 'post',
      data: {
        signature: that.data.sign
      },
      success:function(res){
        wx.hideLoading()
        console.log(res)
        if(res.code==1){
          wx.showToast({
            title: res.msg,
            icon:'none',
            success:function(){
              wx.navigateBack({
                delta: 1
              })
            },
          })
          
        }else{
          wx.showToast({
            title: "请不好重复以前的签名",
            icon: 'none',
            success: function () {
              wx.navigateBack({
                delta: 1
              })
            },
          })
        }
      },
    })
  },
  /**
   * 
   * 添加默认签名
   */
  onShow:function(){
    let sign = wx.getStorageSync("user_info").signature
    let that=this;
    console.log(sign)
    if (sign){
      app.request({
        url: api.user.getsignature,
        method: 'post',
        data: { },
        success: function (res) {
          that.setData({ sign: res.data.signature})
        }
      })
    }

  },
  /**
   * 
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 获取优惠券
    if (options.uid) {
      app.shareCouponsMessage(options.uid)
    }
  },
  // 用户分享
  onShareAppMessage: function () {
    let title = app.shareAppMessage().title;
    let imageUrl = app.shareAppMessage().imageUrl;
    let desc = app.shareAppMessage().desc;
    let path = app.shareAppMessage().path;
    console.log(app.shareAppMessage())
    return {
      title: title,
      imageUrl: imageUrl,
      desc: desc,
      path: path,
    }
  },
  
})